#include "EditorNodeRotationPropertyViewModel.h"

#include "Window/EditorWindowGroupModel.h"
#include "Window/EditorMainWindowModel.h"
#include "Pages/EditorPageModel.h"

#include "Scene/SceneNode.h"

void REditorNodeRotationPropertyViewModel::BindModel(TSharedObjectPtr<REditorPropertyModel> InModel
        ,TSharedObjectPtr<REditorObjectPropertyAbilityViewModel> InAbilityViewModel)
{
    Super::BindModel(InModel,InAbilityViewModel);
    NodeRotationModel = InModel;
}

float REditorNodeRotationPropertyViewModel::GetX() const
{
    return NodeRotationModel->GetX();
}

void REditorNodeRotationPropertyViewModel::SetX(float InX)
{
    auto Page=REditorWindowGroupModel::Get()->GetFocusedPage();
    auto Opearation = NewObject<REditorNodeRotationPropertyOperation>(Page);
    Opearation->Objects.Add(NodeRotationModel->Node);
    SVec3 OldRotation = NodeRotationModel->Node->GetEulerAngleInDegree();
    SVec3 NewRotation = OldRotation;
    NewRotation.X = InX;
    Opearation->ChangeValue(
        NodeRotationModel->Node
        ,OldRotation
        ,NewRotation);

    Page->AddAndRedoOperation(Opearation);
}

float REditorNodeRotationPropertyViewModel::GetY() const
{
    return NodeRotationModel->GetY();
}

void REditorNodeRotationPropertyViewModel::SetY(float InY)
{
    auto Page=REditorWindowGroupModel::Get()->GetFocusedPage();
    auto Opearation = NewObject<REditorNodeRotationPropertyOperation>(Page);
    Opearation->Objects.Add(NodeRotationModel->Node);
    SVec3 OldRotation = NodeRotationModel->Node->GetEulerAngleInDegree();
    SVec3 NewRotation = OldRotation;
    NewRotation.Y = InY;
    Opearation->ChangeValue(
        NodeRotationModel->Node
        ,OldRotation
        ,NewRotation);

    Page->AddAndRedoOperation(Opearation);
}

float REditorNodeRotationPropertyViewModel::GetZ() const
{
    return NodeRotationModel->GetZ();
}

void REditorNodeRotationPropertyViewModel::SetZ(float InZ)
{
    auto Page=REditorWindowGroupModel::Get()->GetFocusedPage();
    auto Opearation = NewObject<REditorNodeRotationPropertyOperation>(Page);
    Opearation->Objects.Add(NodeRotationModel->Node);
    SVec3 OldRotation = NodeRotationModel->Node->GetEulerAngleInDegree();
    SVec3 NewRotation = OldRotation;
    NewRotation.Z = InZ;
    Opearation->ChangeValue(
        NodeRotationModel->Node
        ,OldRotation
        ,NewRotation);

    Page->AddAndRedoOperation(Opearation);
}
